# PRJ
PRJ=jdict
VENDOR=viric
VERSION=0.1

# RTE
WTK2?=/opt/wtk2.2
EMULATOR=${WTK2}/bin/emulator
CLASSPATH=${WTK2}/lib/midpapi10.jar:${WTK2}/lib/cldcapi10.jar:${PRJ}.jar:.
#CLASSPATH=${WTK2}/lib/midpapi.zip:mojab.jar:./src/:.
SRCDIRS=${PRJ}
PKGADDONS=dicts

# TARGETS
all:
	@cd src && mkdir -p output ${SRCDIRS} ${PKGADDONS}
	@echo "==> Building"
	@cd src && \
		javac -g -source 1.2 -target 1.1 -classpath ${CLASSPATH} \
		-bootclasspath ${CLASSPATH} -encoding UTF-8 \
		`find ${SRCDIRS} -type f -iname *.java`
	@echo "==> Preverifying"
	@cd src && \
	${WTK2}/bin/preverify1.1 -classpath ./:${CLASSPATH} \
		`find ${SRCDIRS} |grep class|awk -F . '{ print $$1; }'`

clean:
	@echo "==> Cleaning"
	@rm -rf ${PRJ}.jad ${PRJ}.jar `find src/| grep class` src/output javadoc

doc:
	@echo "==> Generating documentation" 
	@cd src && \
	javadoc -classpath ${CLASSPATH} -d ../javadoc/ \
	`find ${SRCDIRS} -type f -iname *.java`

imatges:
	./makepngs
	rm src/imatges/*
	cp png/* src/imatges

jar:
	@echo "==> Generating JAR file"
	@cd src && cp -rf ${PKGADDONS} output/
	@cd src/output && \
	jar cmf ../META-INF/MANIFEST.MF ../${PRJ}.jar `find .| grep class` ${PKGADDONS}
	@mv src/${PRJ}.jar ./
	@echo "==> Generating manifest for JAD file"
	@echo "MIDlet-1: ${PRJ}, /icons/online.png, ${PRJ}.Main" > ${PRJ}.jad
	@echo "MIDlet-Jar-Size: `ls -l ${PRJ}.jar|awk '{print $$5 }'`" >> ${PRJ}.jad
	@echo "MIDlet-Jar-URL: ${PRJ}.jar" >> ${PRJ}.jad
	@echo "MIDlet-Name: ${PRJ}" >> ${PRJ}.jad
	@echo "MIDlet-Vendor: ${VENDOR}" >> ${PRJ}.jad
	@echo "MIDlet-Version: ${VERSION}" >> ${PRJ}.jad

run:
	@echo "==> Running emulator"
	@${EMULATOR} -classpath ${CLASSPATH} -Xdescriptor:${PRJ}.jad \
	-Xdevice:DefaultColorPhone

debug:
	@echo "==> Running emulator"
	@${EMULATOR} -classpath ${CLASSPATH} -Xdescriptor:${PRJ}.jad \
	-Xdevice:DefaultColorPhone -Xdebug -Xrunjdwp:transport=dt_socket,address=3000,server=y,suspend=n
